# call_soon_threadsafe
import asyncio
from threading import Thread


def start_thread_loop(loop):
    asyncio.set_event_loop(loop)
    loop.run_forever()


def thread_example(name):
    print('正在执行：', name)
    return '返回值：' + name


new_loop = asyncio.new_event_loop()
t = Thread(target=start_thread_loop, args=(new_loop,))
t.start()
handle = new_loop.call_soon_threadsafe(thread_example, 'task_1')
handle.cancel()
new_loop.call_soon_threadsafe(thread_example, 'task_2')
print('主线程不会阻塞')
new_loop.call_soon_threadsafe(thread_example, 'task_3')
print('继续运行中.....')
